package com.car.controller;

import com.car.model.auto.Car;
import com.car.service.ICarService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 达瓦里氏
 * @since 2021-11-30
 */
@RestController
@RequestMapping("/car")
@CrossOrigin
public class CarController {

    @Resource
    private ICarService iCarService;

    /*查询车辆*/
    @GetMapping("/getCar")
    public List<Car> getCar(){
        return iCarService.list();
    }

    /*通过id查询车辆*/
    @GetMapping("/getCarById/{id}")
    public Car getCarById(@PathVariable("id") int id){
        return iCarService.getById(id);
    }

    /*修改车辆*/
    @PostMapping("/updateCar")
    public void updateCar(@RequestBody Car car){
        iCarService.updateById(car);
    }

    /*添加车辆*/
    @PostMapping("/setCar")
    public void setCar(@RequestBody Car car){
        iCarService.save(car);
    }

    /*删除车辆*/
    @PostMapping("/deletedById/{id}")
    public boolean deleted(@PathVariable("id") int id){
        return iCarService.removeById(id);
    }

}
